package com.rxjava.network;

import com.rxjava.network.api.LoginApi;
import com.rxjava.network.api.QRCodeInfoApi;
import com.rxjava.network.api.MeetingInfoApi;

import okhttp3.OkHttpClient;
import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class Network {
    private static LoginApi loginApi;
    private static QRCodeInfoApi qrCodeInfoApi;
	private static MeetingInfoApi meetingInfoApi;
    private static OkHttpClient okHttpClient = new OkHttpClient();
    private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
    private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();

    public static LoginApi getLoginApi(){
        if(loginApi == null){
            Retrofit retrofit = new Retrofit.Builder()
                    .client(okHttpClient)
                    .baseUrl("http://10.225.86.127:8088/admin/jwt/")
                    .addConverterFactory(gsonConverterFactory)
                    .addCallAdapterFactory(rxJavaCallAdapterFactory)
                    .build();
            loginApi = retrofit.create(LoginApi.class);
        }
        return loginApi;
    }

    public static QRCodeInfoApi getQRCodeInfoApi(){
        if(qrCodeInfoApi == null){
            Retrofit retrofit = new Retrofit.Builder()
                    .client(okHttpClient)
                    .baseUrl("http://10.225.86.127:8088/admin/app/")
                    .addConverterFactory(gsonConverterFactory)
                    .addCallAdapterFactory(rxJavaCallAdapterFactory)
                    .build();
            qrCodeInfoApi = retrofit.create(QRCodeInfoApi.class);
        }
        return qrCodeInfoApi;
    }
	
	public static MeetingInfoApi getMeetingInfoApi(){
        if(loginApi == null){
            Retrofit retrofit = new Retrofit.Builder()
                    .client(okHttpClient)
                    .baseUrl("http://10.225.86.127:8088/admin/app/")
                    .addConverterFactory(gsonConverterFactory)
                    .addCallAdapterFactory(rxJavaCallAdapterFactory)
                    .build();
            meetingInfoApi = retrofit.create(MeetingInfoApi.class);
        }
        return meetingInfoApi;
    }

}
